package org.phmanago.gui;

import java.awt.Dimension;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.*;

import org.phmanago.core.Node;
import org.phmanago.utils.FileNode;

/**
 * List containing elements of DataModel
 * @author Marcin Cylke
 *
 */
public class DirPanel extends JList {
	
	private static int rows = 20;
	
	/**
	 * default constructor
	 *
	 */
	public DirPanel () {
		//setPreferredSize(new Dimension(120, 400));
		setVisibleRowCount(rows);
		setCellRenderer(new ImageCellRenderer());
	}
	
	/**
	 * Constructor  - set data model
	 * @param t data model
	 */
	public DirPanel(DefaultListModel t) {
		super(t);
		setVisibleRowCount(rows);
		
	}
	
	/**
	 * change data in the list
	 * @param name
	 */
	public void changed (Vector<FileNode> name) {
		DefaultListModel jlm = new DefaultListModel();
		
		if (name != null) {
			Iterator<FileNode> it = name.iterator();
			while (it.hasNext()) {
				jlm.addElement(it.next());
			}
		}
		this.setModel(jlm);
	}
}
